package com.knoya.chejian.pda.myadapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import com.knoya.chejian.pda.R
import com.knoya.chejian.pda.util.Myutil
import kotlinx.android.synthetic.main.item_pandian.view.*

class PandianAdapter(private var mlist: ArrayList<String>, private val mcontext: Context) : BaseAdapter() {
    private val minflater: LayoutInflater = LayoutInflater.from(mcontext)
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v : View
        var h : Header
        if(convertView==null){
            v=minflater.inflate(R.layout.item_pandian,null)
            h= Header(v)
            v.tag=h
        }else{
            v=convertView
            h=v.tag as Header
        }
        Myutil.settv(mlist[position],h.Tv_Pcode)
        h.Bt_shanchu.setOnClickListener(object : View.OnClickListener{
            override fun onClick(v: View?) {
                mlist.removeAt(position)
                notifyDataSetChanged()
            }

        })
        return v
    }

    override fun getItem(position: Int): Any {
        return mlist[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getCount(): Int {
        return mlist.size
    }

    class Header(var v : View){
        val Tv_Pcode=v.Tv_Pcode
        val Bt_shanchu = v.Bt_shanchu
    }
}